import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  // 存放状态
  state: {
    tagType: ["", "success", "danger", "warning"],
    // 爬虫分类
    dynamicTags: [
      {
        id: 1,
        title: "scrapyd",
        inputVisible: false,
        category: [
          { type: "", label: "think-tank" },
          { type: "", label: "news" },
          { type: "", label: "123456" },
          { type: "", label: "think-tank" },
          { type: "", label: "think-tank" },
        ],
      },
      {
        id: 2,
        title: "python",
        inputVisible: false,
        category: [
          { type: "", label: "think-tank" },
          { type: "", label: "news" },
          { type: "", label: "123456" },

        ],
      },
      {
        id: 3,
        title: "other",
        inputVisible: false,
        category: [
          { type: "", label: "think-tank" },
          { type: "", label: "news" },
          { type: "", label: "123456" },
          { type: "", label: "think-tank" },
          { type: "", label: "think-tank" },
          { type: "", label: "think-tank" },
          { type: "", label: "think-tank" },
        ],
      },
    ],
  },
  // state的计算属性
  getters: {},
  // 更改state中状态的逻辑  同步操作
  mutations: {
    deleteTag() { },
    addTag() { },
    // 给标签添加随机type（颜色）
    addType(state) {
      state.dynamicTags.forEach((val) => {
        val.category.forEach((vals) => {
          vals.type =
            state.tagType[Math.floor(Math.random() * state.tagType.length)];
        });
      });
    },
  },
  // 提交mutations 异步操作
  actions: {},
  // 如果将store分成一个个的模块的话，则需要用到modules。
  //然后在每一个module中写state, getters, mutations, actions等。
  modules: {
    // a: moduleA,
    // b: moduleB,
    // ...
  }
})
